From 3409775ecf982174bd2ae619614e4b4c5c31a545 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Tue, 5 May 2026 16:51:27 +0000 Subject: [PATCH] [PATCH 5/7] lib-sieve: file storage: Remove orphan compiled binaries on delete and rename DELETESCRIPT and RENAMESCRIPT only operated on the .sieve file and left the matching compiled binary (.svbin) on disk. The orphan was never referenced again under that name, so it accumulated as wasted disk space until something else (manual cleanup, account removal) removed it. Unlink fscript->bin_path alongside the .sieve operation. The unlink is best-effort: failures other than ENOENT are logged but do not fail the DELETE/RENAME. Gbp-Pq: Name 0005-lib-sieve-file-storage-Remove-orphan-compiled-binari.patch --- .../lib-sieve/storage/file/sieve-file-script.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/pigeonhole/src/lib-sieve/storage/file/sieve-file-script.c b/pigeonhole/src/lib-sieve/storage/file/sieve-file-script.c index 6cc1dc9..05f8ea3 100644 --- a/pigeonhole/src/lib-sieve/storage/file/sieve-file-script.c +++ b/pigeonhole/src/lib-sieve/storage/file/sieve-file-script.c @@ -659,6 +659,14 @@ static int sieve_file_storage_script_delete(struct sieve_script *script) fscript->path); } } + + /* Best-effort: drop the compiled binary as well so it does not + linger as a stale orphan. */ + if (fscript->bin_path != NULL && + unlink(fscript->bin_path) < 0 && errno != ENOENT) { + e_error(script->event, + "unlink(%s) failed: %m", fscript->bin_path); + } return ret; } @@ -791,6 +799,16 @@ sieve_file_storage_script_rename(struct sieve_script *script, fscript->path); } + /* Drop the old compiled binary; the renamed + script will recompile under its new name. */ + if (fscript->bin_path != NULL && + unlink(fscript->bin_path) < 0 && + errno != ENOENT) { + e_error(script->event, + "unlink(%s) failed: %m", + fscript->bin_path); + } + if (script->name != NULL && *script->name != '\0') script->name = p_strdup(script->pool, newname); fscript->path = p_strdup(script->pool, newpath); -- 2.39.5